package com.lcredu.factory;

import com.lcredu.bean.Monster;

import java.util.HashMap;

/**
 * @author 黎长容
 * @date 2025-07-12 17:39
 */
public class MyStaticFactory {
    private static HashMap<String, Monster> monsterHashMap;

    //在静态代码块中完成初始化
    static {
        monsterHashMap = new HashMap<>();
        monsterHashMap.put("monster01", new Monster(100, "牛魔王", "芭蕉扇"));
        monsterHashMap.put("monster02", new Monster(200, "狐狸精", "美人计"));
    }

    public static Monster getMonster(String monsterId) {
        return monsterHashMap.get(monsterId);
    }
}
